package mysql

import "gorm.io/gorm"

type Goods struct {
	gorm.Model
	Name    string  `gorm:"type:varchar(100);not null;commit:'商品名称'"`
	Price   float64 `gorm:"type:decimal(10,2);not null;commit:'商品价格'"`
	Stock   int64   `gorm:"type:int(11);not null;commit:'商品库存'"`
	Image   string  `gorm:"type:varchar(255);not null"`
	ClassId int64   `gorm:"type:int(11);not null;commit:'分类id'"`
}

func (g *Goods) GoodsAdd(db *gorm.DB) error {
	return db.Debug().Create(g).Error
}

func (g *Goods) FindGoodsByName(db *gorm.DB, name string) error {
	return db.Where("name=?", name).First(g).Error
}
